package com.example.yunJie.digitalSentry.control;

import com.example.yunJie.digitalSentry.entity.ClockEntity;
import com.example.yunJie.digitalSentry.service.*;
import com.example.yunJie.digitalSentry.util.ListPageUtils;
import com.example.yunJie.digitalSentry.util.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/Clock")
public class ClockControl {
    @Autowired
    private ClockService clockService;
    @Autowired
    private PersonalService personalService;
    @Autowired
    private MarketService marketService;
    @Autowired
    private PostService postService;
    @Autowired
    private ShiftService shiftService;
    @Autowired
    private RecognitionService recognitionService;

    @RequestMapping("/add")
    public void insert(ClockEntity clockEntity) {
        clockService.insert(clockEntity);
    }

    @RequestMapping("/update")
    public int update(ClockEntity clockEntity) {
        return clockService.update(clockEntity);
    }

    @RequestMapping("/deleteById")
    public int deleteById(int id) {
        return clockService.deleteById(id);
    }

    @RequestMapping("/deleteIdList")
    public int deleteIdList(List<Integer> id) {
        return clockService.deleteIdList(id);
    }

    @RequestMapping("/findId")
    public ClockEntity findId(Serializable id) {
        return clockService.findId(id);
    }

    @RequestMapping("/findAll")
    public PageParam findAll(ClockEntity clockEntity, int pageNo, int pageSize) throws ParseException {
        List<ClockEntity> all = clockService.findAll(clockEntity);
        //分页后的集合
        List page = ListPageUtils.page(all, pageNo, pageSize);
        //封装给前端的数据
        PageParam pageParam = new PageParam();
        pageParam.setPageNum(pageNo);
        pageParam.setPageSize(pageSize);
        pageParam.setTotalSize(all.size());
        pageParam.setList(page);
        return pageParam;
    }
}
